#!/usr/bin/php -q
<?php

require_once("foto.inc.php");

if (file_exists($otpw_cache)) {
	$r=file($otpw_cache);
	if (check_otpw(trim($r[0]))) {
		echo "[check_otpw] otpw still fine!\n";
		return;
	}
}
$r = getconfig();
if ($r == null ) {
	echo "[get_otpw] Please create $config\n";
	exit;
}
$uid=trim($r[0]);
$pw=trim($r[1]);
$otpw = get_otpw($uid,$pw);
if (!$otpw) {
	echo "[get_otpw] Authentication error\n";
	exit;
}
$fp=fopen($otpw_cache,"w");
fputs($fp, $otpw); fclose($fp);
echo "[get_otpw] $uid authentcated!\n";
?>
